package com.dries.portal.module.coupon.controller;

import cn.hutool.json.JSONUtil;
import com.dries.common.api.CommonResult;
import com.dries.portal.module.coupon.executor.ExecuteManager;
import com.dries.portal.module.coupon.vo.SettlementInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 结算服务
 * @Author ZSY
 * @createTime 2020/8/3 17:05
 */
@Slf4j
@Api(tags = "结算服务API", value = "SettlementController")
@RestController
@RequestMapping("/coupon/settlement")
public class SettlementController {

    /**
     * 结算规则执行管理器
     */
    @Resource
    private ExecuteManager executeManager;

    @ApiOperation("优惠券结算")
    @PostMapping("/compute")
    public CommonResult computeRule(@RequestBody SettlementInfo settlement) {
        log.info("SettlementInfo： {}", JSONUtil.toJsonStr(settlement));

        SettlementInfo info = executeManager.computeRule(settlement);
        return CommonResult.success(info);
    }

}
